package cn.jia.spring7.web.controller;

import cn.jia.spring5.entity.Spittle;
import org.springframework.stereotype.Controller;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.Part;
import javax.validation.Valid;

/**
 * Created by jia on 2018/4/8.
 */
@Controller
public class MultiPartTestController {
    //以byte类型接收参数
    @RequestMapping(value = "multipart",method = RequestMethod.POST)
    public String multipart(@RequestPart("profilePicture") byte[] profilePicture, @Valid Spittle spittle, Errors errors){
        if (errors.hasErrors()){

        }
        return null;
    }
    //以MutipartFile来接收文件参数，不过需要MultipartResolver解析器
    @RequestMapping(value = "multipart",method = RequestMethod.POST)
    public void saveImage(@RequestPart("profilePicture")MultipartFile profilePicture)  {

    }
    //以Part接口来接收文件参数
    @RequestMapping(value = "multipart",method = RequestMethod.POST)
    public void saveImage(@RequestPart("profilePicture")Part profilePicture)  {

    }
}
